//
//  AddViewController.m
//  08-UITableView-Contact
//
//  Created by LL.F on 16/7/25.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "AddViewController.h"
#import "AddView.h"


@interface AddViewController ()
@property (nonatomic, strong) AddView *nameView;
@property (nonatomic, strong) AddView *ageView;
@property (nonatomic, strong) AddView *genderView;
@property (nonatomic, strong) AddView *phoneNumberView;
@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view .backgroundColor = [UIColor whiteColor];
    self.nameView = [[AddView alloc] initWithFrame:CGRectMake(100, 100, 175, 40)];
    _nameView.addTextField.placeholder = @"请输入姓名";
    [self.view addSubview:_nameView];
    
    self.ageView = [[AddView alloc] initWithFrame:CGRectMake(100, 200, 175, 40)];
    _ageView.addTextField.placeholder = @"请输入年龄";
    [self.view addSubview:_ageView];
    
    self.genderView = [[AddView alloc] initWithFrame:CGRectMake(100, 300, 175, 40)];
    _genderView.addTextField.placeholder = @"请输入性别";
    [self.view addSubview:_genderView];
    
    self.phoneNumberView = [[AddView alloc] initWithFrame:CGRectMake(100, 400, 175, 40)];
    _phoneNumberView.addTextField.placeholder = @"请输入联系方式";
    [self.view addSubview:_phoneNumberView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(didClickedSaveButton:)];
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

    [self.view endEditing:YES];
}
// 保存按钮
- (void)didClickedSaveButton:(UIBarButtonItem *)button
{

    NSDictionary *dic = [[NSDictionary alloc] initWithObjects:@[_nameView.addTextField.text, _ageView.addTextField.text, _genderView.addTextField.text, _phoneNumberView.addTextField.text] forKeys:@[@"name", @"age", @"gender", @"phoneNumber"]];
    
    NSLog(@"%@", dic);
    if (self.delegate && [self.delegate respondsToSelector:@selector(PassValue:)]) {
        [self.delegate PassValue:dic];
    }
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
